#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int firstBadVersion(int n)
    {
        long long left = 0;
        long long right = n;
        while (left < right)
        {
            long long mid = (right + left) / 2;
            if (isBadVersion(mid))
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        return (int)left;
    }
};